﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class doctor_student : System.Web.UI.Page
{
    protected Doctor doc;
    protected int guid;
    public Student stu;
    protected void Page_Load(object sender, EventArgs e)
    {
        doc = Doctor.Check();
        if (doc == null)
        {
            Session.Add(Params.SystemError, "请先登录");
            Response.Redirect(Params.RootHttp + "default.aspx");
        }
        this.guid = Convert.ToInt32(Request.Params["guid"]);
        stu = new Student(guid);
        if (!Doctor.DoctorHasStudent(this.doc.Guid, guid))
        {
            Session.Add(Params.SystemError, "发生错误");
            Response.Redirect(Params.DoctorFolderHttp + "students.aspx?uid="+Server.UrlEncode(this.doc.UserID));
        }
        if (!Page.IsPostBack)
        {
            this.MyDataBind();
        }
    }

    public void MyDataBind()
    {
        this.Title = this.doc.RealName + "-浏览学生-"+this.stu.RealName;
        this.conNav.Title = "浏览学生";
        this.labEmail.Text = stu.Email;
        this.labID.Text = stu.UserID;
        this.labName.Text = stu.RealName;
        this.cat.Guid = this.stu.CategoryGuid;
        Paper pap = new Paper(this.guid);
        this.tbKeywords.Text = pap.Keywords.Trim();
        string sql = "select Guid from Paper where StudentGuid="+this.guid.ToString()+" order by Guid asc";
        DataTable dt = Fun.CreateDt(sql);
        this.repPapers.DataSource = dt;
        this.repPapers.DataBind();
        if (this.stu.PaperFlag == 1 || this.stu.PaperFlag ==2)
        {
            this.divUploadPaper.Visible = false;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string f = this.fuPaper.PostedFile.FileName.Trim();
        if (f == "")
        {
            this.info.SetMessage("请选定文件再上传");
            return;
        }
        string kw = this.tbKeywords.Text.Trim();
        if (kw == "")
        {
            this.info.SetMessage("请输入关键字");
            return;
        }
        string intro = this.tbIntro.Text.Trim();
        string fn = System.IO.Path.GetFileNameWithoutExtension(f).Trim();
        string fe = System.IO.Path.GetExtension(f).Trim().ToLower();
        string fn1 = Fun.GetFileName() + fe;
        string fp = Params.FilesFolderPath + fn1;
        this.fuPaper.PostedFile.SaveAs(fp);
        if (System.IO.File.Exists(fp))
        {
            string sql = "insert into Paper(Guid,Title,FileName,Intro,StudentGuid,KeyWords,Flag) values("+Fun.Guid().ToString()+",'" + Fun.L(fn) + "','" + Fun.L(fn1) + "','" + Fun.L(intro) + "'," + this.guid.ToString() + ",'" + Fun.L(kw) + "',3)";
            Fun.Execute(sql);
            bool NeedDistributeExpertToStudent = false;
            if (this.stu.PaperFlag == 0)
            {
                NeedDistributeExpertToStudent = true;
            }
            this.stu.PaperName = fn;
            this.stu.PaperFlag = 3;
            this.stu.CategoryGuid = this.cat.Guid;
            this.stu.Update();
            if (NeedDistributeExpertToStudent)
            {
                Fun.DistributeExpertToStudent(this.stu.Guid);
            }
            Session.Add(Params.SystemError, "提交成功");
        }
        else
        {
            Session.Add(Params.SystemError, "提交失败");
        }
        Response.Redirect(this.Request.RawUrl);
    }
}
